import request from '@/utils/request';

interface UserItem {
  userId: string;
  userName: string;
  account: string;
  password: string;
  createDate: string;
}

interface ListResponse {
  list: UserItem[];
  total: number;
}

export async function qryUserListPage(params: {
  pageIndex?: number;
  pageSize?: number;
  param?: {
    userName?: string;
    account?: string;
  };
}): Promise<ListResponse> {
  const response = await request('/sys/qryUserListPage', {
    method: 'POST',
    data: params,
  });
  return {
    list: response.data || [],
    total: response.total || 0,
  };
}

export async function addUser(params: {
  userName: string;
  account: string;
  password: string;
}): Promise<void> {
  await request('/sys/addUser', {
    method: 'POST',
    data: params,
  });
}

export async function updateUser(params: {
  userId: string;
  userName: string;
  account: string;
  password: string;
}): Promise<void> {
  await request('/sys/updateUser', {
    method: 'POST',
    data: params,
  });
}

export async function deleteUser(params: { userId: string }): Promise<void> {
  await request('/sys/deleteUser', {
    method: 'POST',
    data: params,
  });
}

export async function qryUserDetail(params: {
  userId: string;
}): Promise<UserItem> {
  const response = await request('/sys/qryUserDetail', {
    method: 'POST',
    data: params,
  });
  return response.data;
}
